package com.bw.controller;

import com.bw.been.Hz;
import com.bw.service.HzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class HzController {

    @Autowired
    HzService hzService;

    //②	测试添加方法
    @RequestMapping("add")
    public int add(){
        Hz hz = new Hz(7,"吴起","男","16354715896","41157964152485246",44,
                1,"手术治疗",1,"未绑定",null,"2024-05-14","2024-07-24");
        return hzService.add(hz);
    }

    //③	测试批量添加的方法
    @RequestMapping("adds")
    public int adds(){
        Hz hz1 = new Hz(8,"小白","男","16354715896","41157964152485246",44,
                1,"手术治疗",1,"未绑定",null,"2024-05-14","2024-07-24");
        Hz hz2 = new Hz(9,"灰灰","男","16354715896","41157964152485246",44,
                1,"手术治疗",1,"未绑定",null,"2024-05-14","2024-07-24");
        Hz[] hzs = {hz1,hz2};
        return hzService.adds(hzs);
    }

    //④	测试删除方法
    @RequestMapping("del")
    public int del(){
        Integer hid = 7;
        return hzService.del(hid);
    }

    //⑤	测试批量删除方法
    @RequestMapping("dels")
    public int dels(){
        int[] ids = {8,9};
        return hzService.dels(ids);
    }

    //多条件组合查询
    @RequestMapping("getList")
    public List getList(){
        Map<String, Object> map = new HashMap<>();
        //姓名模糊
        String name = "花";
        //年龄区间
        Integer age1 = 30;
        Integer age2 = 40;
        map.put("name",name);
        map.put("age1",age1);
        map.put("age2",age2);
        List<Hz> list = hzService.getList(map);
        return list;
    }
}
